package com.lsy.weizhi2.customview;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lsy.weizhi2.R;
import com.lsy.weizhi2.myutils.ReplyDailogCall;

/**
 * Created by 嗨哟 on 2017/3/16.
 */
public class ReplyDailog extends RelativeLayout {
    private EditText reply_input_et;
    private TextView reply_cancel,reply_ok;
    private String hint,ok;
    private ReplyDailogCall replyDailogCall;
    public ReplyDailog(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.reply_dailog,this,true);
        TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.ReplyDialog);
        hint=typedArray.getString(R.styleable.ReplyDialog_hint_text);
        ok=typedArray.getString(R.styleable.ReplyDialog_click_ok);
        typedArray.recycle();
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        reply_input_et= (EditText) findViewById(R.id.reply_input_et);
        reply_cancel= (TextView) findViewById(R.id.reply_cancel);
        reply_ok= (TextView) findViewById(R.id.reply_ok);
        if(!TextUtils.isEmpty(hint)){
            reply_input_et.setHint(hint);
        }
        if(!TextUtils.isEmpty(ok)){
            reply_ok.setText(ok);
        }
        reply_ok.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                replyDailogCall.onClick(view,ReplyDailogCall.OK);
            }
        });
        reply_cancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                replyDailogCall.onClick(view,ReplyDailogCall.CANCEL);
            }
        });
    }

    /**
     * 获取输入框内的文字
     * @return
     */
    public String getText(){
        return reply_input_et.getText().toString().trim();
    }

    /**
     * 引用时-预加载
     * @param info
     */
    public void setText(String info){
        reply_input_et.setText(info);
    }
    /**
     * 点击事件回调
     * @param replyDailogCall
     */
    public void setReplyDailogCall(ReplyDailogCall replyDailogCall){
        this.replyDailogCall=replyDailogCall;
    }
}
